<template>
  <div>
    <el-container>
      <el-header height="70px">
        <p class="header_title">角色管理</p>
        <!--  -->
        <el-breadcrumb separator="/">
          <el-breadcrumb-item>权限维护</el-breadcrumb-item>
          <el-breadcrumb-item>角色管理</el-breadcrumb-item>
          <el-breadcrumb-item><b>添加角色</b></el-breadcrumb-item>
        </el-breadcrumb>
      </el-header>

      <el-main>
        <el-card class="box-card">
          <div slot="header">
            <span>添加角色</span>
            <span>{{this.id}}</span>
          </div>

          <!-- 0 -->
          <el-row :gutter="50">
            <el-col :span="10">
              <p class="hasList">已经分配行为列表</p>
              <el-pagination
                @size-change="handleSizeChange1"
                @current-change="handleCurrentChange1"
                :current-page="pagination1.pagenum"
                :page-sizes="[1, 3, 5, 10]"
                :page-size="pagination1.pagesize"
                layout="total, sizes"
                :total="pagination1.total"
              >
              </el-pagination>
              <el-table :data="pagelist1" border stripe>
                <el-table-column label="名称" prop="name"></el-table-column>
                <el-table-column label="操作">
                  <template slot-scope="scope">
                    <el-button
                      type="primary"
                      size="mini"
                      @click="delete scope.row"
                      >取消</el-button
                    >
                  </template>
                </el-table-column>
              </el-table>
              <el-pagination
                @size-change="handleSizeChange1"
                @current-change="handleCurrentChange1"
                :current-page="pagination1.pagenum"
                :page-size="pagination1.pagesize"
                background
                layout="prev, pager, next"
                :total="pagination1.total"
              >
              </el-pagination>
            </el-col>

            <el-col :span="10">
              <el-row>
                <!-- 页数展示 -->
                <el-col>
                  <p class="notList">行为列表</p>
                  <span>
                    <el-pagination
                      @size-change="handleSizeChange"
                      @current-change="handleCurrentChange"
                      :page-sizes="[1, 3, 5, 10]"
                      :page-size="pagination.pagesize"
                      layout=" sizes,total"
                      :total="pagination.total"
                    >
                    </el-pagination>
                  </span>
                </el-col>
              </el-row>

            <!-- 行为列表表单 -->
              <el-table
                :data="pagelist"
                border
                stripe
                :row-class-name="tableRowClassName"
              >
                <el-table-column label="名称" prop="name"></el-table-column>
                <el-table-column label="操作">
                  <template slot-scope="scope">
                    <el-button
                      type="primary"
                      size="mini"
                      @click="allot(scope.row)"
                      >分配</el-button
                    >
                    <el-button size="mini" @click="update(scope.row)">更新权限</el-button>
                  </template>
                </el-table-column>
              </el-table>
            <!-- 行为列表底部分页器 -->
              <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="pagination.pagenum"
                :page-size="pagination.pagesize"
                background
                layout="prev, pager, next"
                :total="pagination.total"
              >
              </el-pagination>
            </el-col>
          </el-row>

        </el-card>
        <!-- card结束区域 -->
      </el-main>
    </el-container>
  </div>
</template>

<script>
export default {
  data() {
    return {
      id:this.$route.query.id,
      // noAuth为角色添加未添加的行为
      notAuthInfo: {
        total: "",
        notAuth: "",
      },
      noAuthlist: [],
      pagination: {
        id: this.$route.query.id,
        pagenum: 1,
        pagesize: 5,
        total: 2,
      },
      pagelist: [],
      // hasAuth为对应角色显示已有的行为
      hasAuthInfo: {
        total: "",
        hasAuth: "",
      },
      pagination1: {
        id: this.$route.query.id,
        pagenum: 1,
        pagesize: 3,
      },
      pagelist1: [],
      //
    };
  },
  methods: {
    // 隔行变色
    tableRowClassName({ row, rowIndex }) {
      if (rowIndex === 1) {
        return "warning-row";
      } else if (rowIndex === 3) {
        return "success-row";
      }
      return "";
    },
    // notAuth
    async getNotAuthList() {
      const res = await this.http.get(
        "roleAuth/select/notAuth",
        this.pagination
      );
      this.pagelist = res.notAuth;
      this.pagination.total = res.total;
    },
    handleSizeChange(newSize) {
      this.pagination.pagesize = newSize;
      this.getNotAuthList();
    },
    handleCurrentChange(newPage) {
      this.pagination.pagenum = newPage;
      this.getNotAuthList();
    },
    // hasAuth /roleAuth/select/hasAuth
    async getHasAuthList() {
      const res = await this.http.get(
        "/roleAuth/select/hasAuth",
        this.pagination1
      );
      this.pagelist1 = res.hasAuth;
      this.pagination1.total = res.total;
    },
    handleSizeChange1(newSize) {
      this.pagination1.pagesize = newSize;
      this.getHasAuthList();
    },
    handleCurrentChange1(newPage) {
      this.pagination1.pagenum = newPage;
      this.getHasAuthList();
    },

    // 角色表-提供行为分配
    allot(row) {
      const res = this.http.post('/roleAuth/add',{aid:1,rid:1})
      console.log(res);
    },
    // 角色表-取消已存在的行为
    delete(row) {},
    // 
    update(row){

      
    }
  },
  created() {
    this.getNotAuthList(), this.getHasAuthList();
  },
};
</script>

<style scoped>
.el-input {
  margin-bottom: 20px;
}
.el-pagination {
  width: 100px;
}
.search {
  margin-top: -70px;
  margin-left: 200px;
}
.search .el-input {
  margin-top: 10px;
}
/* 表单隔行变色 */
.el-table .warning-row {
  background: oldlace;
}

.el-table .success-row {
  background: #f0f9eb;
}
.hasList {
  border-bottom: 5px solid yellow;
  width: 140px;
}
.notList {
  border-bottom: 5px solid lightgreen;
  width: 80px;
}
/* 搜索框 */
.searchIcon{
  width: 300px;
}
</style>
